﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Constraints;
using System.Globalization;

namespace TimScripts.BF4Rcon.Test
{
    [TestFixture]
    public class PlayerTests
    {
        private const string Name = "testname";
        private TestPlayer Player1;
        private const int TeamId = 1337;
        private const int SquadId = 2;

        [SetUp]
        public void SetUp()
        {
            Player1 = new TestPlayer();

            Player1.Props.Add("name", Name);
            Player1.Props.Add("teamId", TeamId.ToString(CultureInfo.InvariantCulture));
            Player1.Props.Add("squadId", SquadId.ToString(CultureInfo.InvariantCulture));
        }

        [Test]
        public void TryGetProperty()
        {
            string value;
            bool result = Player1.TryGetProperty("name", out value);

            Assert.AreEqual(true, result);
            Assert.AreEqual(Player1["name"], value);
        }

        [Test]
        public void DynamicPlayerGetsProperty()
        {
            dynamic player = Player1;

            Assert.AreEqual(TeamId, player.TeamId);
        }

        [Test]
        public void DynamicPlayerTeamAlias()
        {
            dynamic player = Player1;

            Player1.AddAlias("team", "teamid");

            Assert.AreEqual(TeamId, player.Team);
        }

        private class TestPlayer : Player
        {
            public Dictionary<string, string> Props = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

            public override string this[string key]
            {
                get { return Props[key]; }
            }

            public override bool TryGetProperty(string key, out string value)
            {
                return Props.TryGetValue(key, out value);
            }

            public new void AddAlias(string alias, string actual)
            {
                base.AddAlias(alias, actual);
            }

            public override bool ContainsProperty(string key)
            {
                throw new NotImplementedException();
            }
        }
    }
}
